Set correct event type into SimulateNative methods #11563
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit fixes an issue where events generated by the test utils had no type. These events are not real DOM Event objects and their constructor did not assign the provided event type property:
This through me for a bit of a loop because I didn't realize the
Event
class was defined locally to this module; that it wasn't a DOM event. I've renamed this constructor toFakeNativeEvent
for clarity.Additionally, it looks like the Event object was being constructed with the top level type (
topClick
vsclick
). This commit ensures that ReactTestUtils.Simulate and ReactTestUtils.SimulateNative correctly assign the event type.Why does this matter?
Working through #11550, which evaluates assigning local listeners instead of event delegation, one of the biggest pieces of overhead is the
dispatchEvent.bind(topLevelType)
done for every event attachment. I believe we could just use the event type, avoiding the cost of the bind.Other questions
Do we need a fake event constructor? Is it incorrect for
ReactTestUtils.SimulateNative
to dispatch a fake DOM event instead of just using the DOM Event constructor?